import { globalStyle } from '@/components/global-config/style/style'
import { deepCopy } from '@/function'
import buttonComponent from './items/submitButton/data'
export const data = {
    name: 'form',
    data: {
        id: '',
        label : '默认表单名称', // 表单名称
        style: Object.assign(deepCopy(globalStyle),{
            backgroundColor: 'white'
        }),
        components : [

        ],
    },
    label: {
        name: "表单",
        icon: 'orders-o',
        type: "component-form-label",
    },
    render: {
        type: "component-form-render",
        component: import('./render.vue')
    },
    preview: {
        type: "component-form-preview",
        component: import('./preview.vue')
    },
    config: {
        type: "component-form-config",
        component: import('./config.vue')
    },
};

export const getFieldData = (data) => {
    let obj = {
        formId : data.id,
        data : []
    };
    data.components.forEach(function (component) {
        //首先排除提交按钮的组件
        if (component.name === buttonComponent.name){
            return
        }
        let fieldValue = {
            label : component.data.label,
            field : component.data.fieldName,
            value : component.data.value,
        };
        if(component.data.repeatCheck !== undefined && parseInt(component.data.repeatCheck) === 1){
            fieldValue.repeatCheck = true;
        }
        if (component.data.options !== undefined){
            fieldValue.options = component.data.options
        }
        obj.data.push(fieldValue)
    });
    return obj
}

export const name = data.name